package com.ruoyi.workbench.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.workbench.domain.WorkTargetTask;
import com.ruoyi.workbench.mapper.WorkTargetTaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.workbench.mapper.WorkTargetMapper;
import com.ruoyi.workbench.domain.WorkTarget;
import com.ruoyi.workbench.service.IWorkTargetService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 年度考核指标Service业务层处理
 * 
 * @author Guojl
 * @date 2024-07-04
 */
@Service
public class WorkTargetServiceImpl implements IWorkTargetService 
{
    @Autowired
    private WorkTargetMapper workTargetMapper;

    @Autowired
    private WorkTargetTaskMapper workTargetTaskMapper;

    /**
     * 查询年度考核指标
     * 
     * @param targetId 年度考核指标主键
     * @return 年度考核指标
     */
    @Override
    public WorkTarget selectWorkTargetByTargetId(Long targetId)
    {
        return workTargetMapper.selectWorkTargetByTargetId(targetId);
    }

    /**
     * 查询年度考核指标列表
     * 
     * @param workTarget 年度考核指标
     * @return 年度考核指标
     */
    @Override
    public List<WorkTarget> selectWorkTargetList(WorkTarget workTarget)
    {
        return workTargetMapper.selectWorkTargetList(workTarget);
    }

    /**
     * 新增年度考核指标
     * 
     * @param workTarget 年度考核指标
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int insertWorkTarget(WorkTarget workTarget)
    {
        workTarget.setCreateTime(DateUtils.getNowDate());
        workTarget.setCreateBy(SecurityUtils.getUserId().toString());
        return workTargetMapper.insertWorkTarget(workTarget);
    }

    /**
     * 修改年度考核指标
     * 
     * @param workTarget 年度考核指标
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int updateWorkTarget(WorkTarget workTarget)
    {
        workTarget.setUpdateTime(DateUtils.getNowDate());
        workTarget.setUpdateBy(SecurityUtils.getUserId().toString());
        return workTargetMapper.updateWorkTarget(workTarget);
    }

    /**
     * 批量删除年度考核指标
     * 
     * @param targetIds 需要删除的年度考核指标主键
     * @return 结果
     */
    @Override
    public int deleteWorkTargetByTargetIds(Long[] targetIds)
    {
        return workTargetMapper.deleteWorkTargetByTargetIds(targetIds);
    }

    /**
     * 删除年度考核指标信息
     * 
     * @param targetId 年度考核指标主键
     * @return 结果
     */
    @Override
    public int deleteWorkTargetByTargetId(Long targetId)
    {
        return workTargetMapper.deleteWorkTargetByTargetId(targetId);
    }
}
